scrolledwindow: Avoid using gtk_widget_get_preferred_size
authorTimm Bäder <mail@baedert.org>
Sun, 22 Dec 2019 09:42:51 +0000 (10:42 +0100)
committerTimm Bäder <mail@baedert.org>
Tue, 7 Jan 2020 16:27:17 +0000 (17:27 +0100)
This way we only measure in the direction we need.

gtk/gtkscrolledwindow.c

index cddf1c222ba414134dfde0707fcf911da89e2d8c..e82601a53092ec78b6cdc7663425314446ae68a7 100644 (file)
@@ -1728,35 +1728,50 @@ gtk_scrolled_window_measure (GtkWidget      *widget,
    */
   if (policy_may_be_visible (priv->hscrollbar_policy))
     {
-      GtkRequisition hscrollbar_requisition;
-      gtk_widget_get_preferred_size (priv->hscrollbar, &hscrollbar_requisition, NULL);
-
       if (orientation == GTK_ORIENTATION_HORIZONTAL)
         {
-          minimum_req = MAX (minimum_req, hscrollbar_requisition.width + sborder.left + sborder.right);
-          natural_req = MAX (natural_req, hscrollbar_requisition.width + sborder.left + sborder.right);
+          int min_scrollbar_width, nat_scrollbar_width;
+
+          gtk_widget_measure (priv->hscrollbar, GTK_ORIENTATION_HORIZONTAL, -1,
+                              &min_scrollbar_width, &nat_scrollbar_width,
+                              NULL, NULL);
+          minimum_req = MAX (minimum_req, min_scrollbar_width + sborder.left + sborder.right);
+          natural_req = MAX (natural_req, nat_scrollbar_width + sborder.left + sborder.right);
         }
       else if (!priv->use_indicators && priv->hscrollbar_policy == GTK_POLICY_ALWAYS)
         {
-          minimum_req += hscrollbar_requisition.height;
-          natural_req += hscrollbar_requisition.height;
+          int min_scrollbar_height, nat_scrollbar_height;
+
+          gtk_widget_measure (priv->hscrollbar, GTK_ORIENTATION_VERTICAL, -1,
+                              &min_scrollbar_height, &nat_scrollbar_height,
+                              NULL, NULL);
+
+          minimum_req += min_scrollbar_height;
+          natural_req += nat_scrollbar_height;
         }
     }
 
   if (policy_may_be_visible (priv->vscrollbar_policy))
     {
-      GtkRequisition vscrollbar_requisition;
-      gtk_widget_get_preferred_size (priv->vscrollbar, &vscrollbar_requisition, NULL);
-
       if (orientation == GTK_ORIENTATION_VERTICAL)
         {
-          minimum_req = MAX (minimum_req, vscrollbar_requisition.height + sborder.top + sborder.bottom);
-          natural_req = MAX (natural_req, vscrollbar_requisition.height + sborder.top + sborder.bottom);
+          int min_scrollbar_height, nat_scrollbar_height;
+
+          gtk_widget_measure (priv->vscrollbar, GTK_ORIENTATION_VERTICAL, -1,
+                              &min_scrollbar_height, &nat_scrollbar_height,
+                              NULL, NULL);
+          minimum_req = MAX (minimum_req, min_scrollbar_height + sborder.top + sborder.bottom);
+          natural_req = MAX (natural_req, nat_scrollbar_height + sborder.top + sborder.bottom);
         }
       else if (!priv->use_indicators && priv->vscrollbar_policy == GTK_POLICY_ALWAYS)
         {
-          minimum_req += vscrollbar_requisition.width;
-          natural_req += vscrollbar_requisition.width;
+          int min_scrollbar_width, nat_scrollbar_width;
+
+          gtk_widget_measure (priv->vscrollbar, GTK_ORIENTATION_HORIZONTAL, -1,
+                              &min_scrollbar_width, &nat_scrollbar_width,
+                              NULL, NULL);
+          minimum_req += min_scrollbar_width;
+          natural_req += nat_scrollbar_width;
         }
     }